package inet.app.tuvi.base;

import inet.app.tuvi.MyApplication;
import inet.app.tuvi.util.MyPreferenceManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Window;
import android.view.WindowManager;

public class BaseFragmentActivity extends FragmentActivity {
	
	protected MyApplication mApplication;
	protected MyPreferenceManager mPreferenceManager;
	protected FragmentManager mFragmentManager;

	@Override
	protected void onCreate(Bundle bundle) {
		super.onCreate(bundle);

		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		// Switch to fullscreen view, getting rid of the status bar as well.
		// this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
		// hide the keyboard everytime the activty starts
		getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

		mPreferenceManager = MyPreferenceManager
				.getInstance(getApplicationContext());

		mApplication = (MyApplication) getApplication();
		
		mFragmentManager = getSupportFragmentManager();

	}
	
	/**
	 * Remove previous show dialog fragment by tag
	 * 
	 * @param tag
	 *            tag of dialog fragment
	 */
	protected void removePreviousDialog(String tag) {
		// DialogFragment.show() will take care of adding the fragment
		// in a transaction. We also want to remove any currently showing
		// dialog, so make our own transaction and take care of that here.
		FragmentTransaction ft = mFragmentManager.beginTransaction();
		Fragment prev = mFragmentManager.findFragmentByTag(tag);
		if (prev != null) {
			ft.remove(prev);
		}
		ft.addToBackStack(null);
		ft.commit();
	}

}
